import { httpV3 } from '../httpV3';

/**
 * @description: 材料相关的HTTP API V3版本
 */
export const materialHttpApi = {
  // 获取材料库树形结构
  getMaterialLibrary: () => httpV3.post(`/api/v3/material/tree`),
  // 新增材料库
  addMaterialLibrary: ({ libraryName }: { libraryName: string }) =>
    httpV3.post(`/api/v3/materialCollection/save`, {
      name: libraryName,
    }),
  // 收藏材料
  favMaterial: ({ materialId }: { materialId: string }) =>
    httpV3.post(`/api/v3/collect/toCollect`, { materialId }),
  // 取消材料
  unFavMaterial: ({ id }: { id: string }) =>
    httpV3.post(`/api/v3/collect/cancleCollect`, { id }),
  // 添加材料种类
  addMaterialCategory: ({
    name,
    materialCollectionId,
  }: {
    materialCollectionId: string;
    name: string;
  }) =>
    httpV3.post(`/api/v3/materialType/save`, {
      name,
      materialCollectionId,
    }),
  // 重命名材料库
  renameMaterialLibrary: ({ name, id }: { name: string; id: string }) =>
    httpV3.post(`/api/v3/materialCollection/rename`, {
      name,
      id,
    }),
  // 重命名材料类型
  renameMaterialCategory: ({ name, id }: { name: string; id: string }) =>
    httpV3.post(`/api/v3/materialType/rename`, { name, id }),
  // 重命名材料
  renameMaterial: ({ name, id }: { name: string; id: string }) =>
    httpV3.post(`/api/v3/material/rename`, { name, id }),
  // 删除材料库
  delMaterialLib: ({ id }: { id: string }) =>
    httpV3.post(`/api/v3/materialCollection/delete?id=${id}`),
  // 删除材料类别
  delMaterialCat: ({ id }: { id: string }) =>
    httpV3.post(`/api/v3/materialType/delete?id=${id}`),
  // 删除材料
  delMaterial: ({ id }: { id: string }) =>
    httpV3.post(`/api/v3/material/delete`, { materialId: id }),
  // 新建材料
  newMaterial2Cat: ({
    materialTypeId,
    name,
  }: {
    name: string;
    materialTypeId: string;
  }) =>
    httpV3.post(`/api/v3/material/save`, {
      name,
      materialTypeId,
    }),

  // 粘贴材质
  pasteMaterial2Cat: ({
    materialTypeId,
    materialId,
  }: {
    materialId: string;
    materialTypeId: string;
  }) =>
    httpV3.post(`/api/v3/materialType/paste`, {
      materialId,
      materialTypeId,
    }),

  // 获取材质详情
  getMaterialDetail: ({ source, id }: { source: string; id: string }) =>
    httpV3.post(`/api/v3/material/detailInfo`, {
      source,
      id,
    }),

  // 保存修改后的材质
  saveMaterialDetail: (params: CmdMaterialSpace.MaterialUpdateDetail) =>
    httpV3.post(`/api/v3/material/update`, params),
};
